package com.bjpowernode.contoller;

import com.bjpowernode.POJO.Admin;
import com.bjpowernode.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/admin")
public class AdminAction {
    // 切记：在所有的界面层，一定会有业务逻辑层的对象
    @Autowired
    private AdminService adminService;
    // 实现登录判断，并进行相应的跳转
    @RequestMapping("/login")
    public ModelAndView login(String name, String pwd){
        ModelAndView modelAndView = new ModelAndView();

        System.out.println(name);
        System.out.println(pwd);

        Admin login = adminService.login(name, pwd);
        if(login != null){
            // 登录成功
            modelAndView.addObject("admin",login);
            modelAndView.setViewName("main");
            return modelAndView;
        }else{
            // 登录失败
            modelAndView.addObject("errmsg","用户名和密码不正确！");
            modelAndView.setViewName("login");
            return modelAndView;
        }
    }
}
